package l.l.w.UnderstandingJVM.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * Created by llw on 2018/5/11/0011.
 */
public class Test2 {


    public static void main(String[] args) {
        System.getProperties().put("sun.misc.ProxyGenerator.saveGeneratedFiles", "true");
        UserDao userDao = new UserDaoImpl();
        UserDao userDaoProxy1 = (UserDao) Proxy.newProxyInstance(userDao.getClass().getClassLoader(), userDao.getClass().getInterfaces(), new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println("before1");
                Object invoke = method.invoke(userDao, args);
                System.out.println("after1");
                return invoke;
            }
        });
        userDaoProxy1.insert(10);
    }
}
